package net.huashitong.Indicators.service;

import com.sirdc.modules.sys.entity.SysScheduleJob;
import com.sirdc.modules.sys.filter.SysScheduleJobFilter;

import net.huashitong.Indicators.dto.OverInfoDTO;
import net.huashitong.Indicators.entity.BA01;
import net.huashitong.Indicators.entity.BA02;
import net.huashitong.Indicators.filter.BA01Filter;
import net.huashitong.until.Until;
import org.quartz.SchedulerException;


import java.util.List;
import java.util.TimerTask;

public class OverCourseJobService extends TimerTask {

   private OverInfoDTO dto;

    public OverCourseJobService(OverInfoDTO dto) {
       this.dto=dto;
    }

    @Override
    public void run() {

        System.out.println("-----------选课结束时间" + dto.getMessage() + "------");
        //停止账户余额的值
        SysScheduleJobFilter filter  = new SysScheduleJobFilter();
        filter.setJobName("JobService");
        List<SysScheduleJob> list  = dto.getScheJobService().getJobs(filter);
        try {
            //停止每分钟 减少1
            dto.getScheduleJobService().updateStatus2Pause(list.get(0).getSysId());
        } catch (SchedulerException e) {
            e.printStackTrace();
        }


        dto.getRedisService().set("choosestatue","0");

        //先选出所有的课程和课程名额，
        List<BA01>  ba01s =dto.getBa01Service().getAllCourse(new BA01Filter());
        for(BA01 item:ba01s)
        {// 筛选出结果
          // (item.getBAB001().trim(),item.getBAB003().trim());//筛选选课结果
            dto.getAb02Service().batchAccount(item.getBAB001().trim(),item.getBAB003().trim(),dto.getRedisService().get(Until.SmesterDate));//筛选选课结果;
        }
        //已经筛选出结果

        dto.getRedisService().set("resultCode","1");  //已经有结果 1 ，没有结果0
        //String courseDate = Until.getHalfYear(Until.getCurrentDate());
        String courseDate  = dto.getRedisService().get("semesterDate");
        BA02 ba02 = dto.getBa02Service().getDate(courseDate);
        ba02.setBAB204("1");
        ba02.setAAA100("0");//选课结束，标志位0
        dto.getBa02Service().update(ba02);
    }
}
